package dfbz.homework8;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class Test {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        Student student1 = new Student("张三",55.5);
        Student student2 = new Student("张三",77.2);
        Student student3 = new Student("张三",66.6);
        Student student4 = new Student("张三",70.1);
        Collections.addAll(students,student1,student2,student3,student4);
        System.out.println(students.toString());
        Collections.sort(students, ( o1, o2)->{
                int result= (int) (o2.getScore()-o1.getScore());
                if(result==0){
                    result=o2.getName().charAt(0)-o1.getName().charAt(0);
                }
                return result;
        });
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()){
            Student next = iterator.next();
            System.out.println(next.getName()+"---"+next.getScore());
        }
    }
}
